package com.ecable.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ecable.bean.DistrictTO;
import com.ecable.bean.ProfileTO;
import com.ecable.delegate.DistrictMgrDelegate;
import com.ecable.exception.ConnectionException;
import com.ecable.exception.DataNotFoundException;
import com.ecable.util.UtilConstants;

public class ViewRegVillageDistrictAction extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4229229798006038995L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		RequestDispatcher rd=null;

		Vector<DistrictTO> vdto=null;
		String path="";
		String sname=null;
		//String usertype=request.getParameter("usertype");
		try{
			
			DistrictMgrDelegate dmd=new DistrictMgrDelegate();
			
			
			try
			{
				
				sname=request.getParameter("sname");
				
				System.out.println("in action class..........."+sname);
				vdto=dmd.getDistName(sname);
				}
			
			catch (ConnectionException ce) {
				throw new ServletException("server busy please try again");
			}
			
			catch (DataNotFoundException le) {
				request.setAttribute("status", UtilConstants._ALL_DISTRICT_FAILED);
				rd=request.getRequestDispatcher(UtilConstants._LOGIN_FAILED_PAGE);
			}
			
            if(vdto!=null){
				
				request.setAttribute("dist", vdto);
				request.setAttribute("statename", sname);
				//request.setAttribute("usertype", usertype);
						path=UtilConstants._REG_ADDRESS_PAGE;
				System.out.println(path);
				}
			else{
				
				request.setAttribute("status", UtilConstants._ALL_DISTRICT_FAILED);
				//request.setAttribute("usertype", usertype);
				path=UtilConstants._REG_ADDRESS_PAGE;
				
			}
		}
		catch (ServletException e) {
			
			e.printStackTrace();
			
		}
		
		rd=request.getRequestDispatcher(path);
		rd.forward(request, response);
		
		
	}

		
		
	}


